#include <iostream>
#include <algorithm>
using namespace std;
struct data{
	int length;
	int dia;
	int code;
};

bool cmp(data a,data b)
{
	if(a.length<b.length) return true;
	else if(a.length==b.length){
		if(a.dia>b.dia) return true;
		else if(a.dia==b.dia) {
			return a.code<b.code;
		}
		else return false;
	}
	else return false;
}
data src[10000];

int main()
{
	int t;
	while(cin>>t){
		for(int i=0;i<t;i++){
			int k;
			cin>>k;
			for(int j=0;j<k;j++) cin>>src[j].length>>src[j].dia>>src[j].code;
			sort(src,src+k,cmp);
			cout<<src[k-1].code<<endl;
		}
		
	}
}
